<template>
  <div>
  <!--面包屑导航区-->
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>商品管理</el-breadcrumb-item>
    <el-breadcrumb-item>添加商品</el-breadcrumb-item>
  </el-breadcrumb>

  <!--卡片视图区-->
  <el-card>
    <el-row>
      <el-col :span="8">
        <el-input placeholder="请输入内容">
          <el-button slot="append" icon="el-icon-search"></el-button>
        </el-input>
      </el-col>
    </el-row>
    <el-row>
      <!--订单列表数据-->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index" label="#">

        </el-table-column>
        <el-table-column label="订单编号" prop="order_number">

        </el-table-column>
        <el-table-column label="订单价格" prop="order_price">

        </el-table-column>
        <el-table-column label="是否付款" prop="pay_status">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status == '1'">已付款</el-tag>
            <el-tag v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send">

        </el-table-column>
        <el-table-column label="下单时间" prop="create_time">
             <template slot-scope="scope">
               {{scope.row.create_time | dateFormat}}
             </template>
        </el-table-column>
        <el-table-column label="操作">
         <template slot-scope="scope">
           <el-button type="primary" icon="el-icon-edit" size="mini" @click="showBox"></el-button>
           <el-button type="success" icon="el-icon-location" size="mini" @click="showLocation"></el-button>
         </template>
        </el-table-column>
      </el-table>
    </el-row>

    <!--分页区域-->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :current-page="querInfo.pagenum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="querInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </el-card>
    <!--点击修改对话框-->
    <el-dialog title="修改对话框" :visible.sync="editDialogVisible" width="50%" @close="editFormDialogClose">
      <!--带验证规则的表单-->
      <el-form :model="editForm" :rules="editFormRules" ref="editFormRef" label-width="100px" class="demo-ruleForm">
        <el-form-item label="省市/区" prop="addressM" >
          <el-cascader expand-trigger="hover"
            v-model="editForm.addressM"
            :options="cityData"
            @change="handleChange"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="addressP">
          <el-input v-model="editForm.addressP"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
    <el-button @click="editDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="editDialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>

    <!--物流信息对话框-->
    <el-dialog title="查看物流信息" :visible.sync="ProgressDialogVisible" width="50%" >
      <!--时间线-->
      <el-timeline :reverse="true">
        <el-timeline-item
          v-for="(activity, index) in progressInfo"
          :key="index"
          :timestamp="activity.time">
          {{activity.context}}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>

</template>

<script>
  import cityData from './citydata.js'
    export default {
        name: "Order",
      data(){
          return {
            querInfo: {
              query:'',
              pagenum:1,
              pagesize:10
            },
          // 订单总条数
            total:0,
           //订单列表
            orderList:[],
            //控制对话框显示隐藏
            editDialogVisible:false,
            //修改对话框验证规则
            editForm:{
              addressM:'',
              addressP:''
            },
            //修改对话框验证规则
            editFormRules:{
              addressM:[{ required: true, message: '请输入省/市/区县', trigger: 'blur' }],
              addressP:[{ required: true, message: '请选择详细地址', trigger: 'blur' }]
            },
            cityData,
            //物流信息显示与否
            ProgressDialogVisible:false,
            //物流信息
            progressInfo:[ ]
          }
      },
      created(){
         this.getOrderList()
      },
      methods:{
       async getOrderList(){
       const {data:res}= await this.axios.get('orders',{params:this.querInfo})
           if (res.meta.status !== 200){
             this.$memege.error('获取列表失败！')
           }

           this.total = res.data.total
         this.orderList = res.data.goods
         console.log(this.orderList);
       },
        handleSizeChange(newSize){
         this.querInfo.pagesize = newSize
          this.getOrderList()
        },
        handleCurrentChange(newPage){
         this.querInfo.pagenum = newPage
          this.getOrderList()
        },
        showBox(){
         this.editDialogVisible = true
        },
        //级联选择省市县
        handleChange(){

        },
        //关闭对话框重置
        editFormDialogClose(){
         this.$refs.editFormRef.resetFields()
        },
        //显示物流信息
       async showLocation(){
       const {data:res}= await this.axios.get(`/kuaidi/1106975712663`)
           this.ProgressDialogVisible = true
          if (res.meta.status !== 200) {
            return this.$memege.error('获取物流信息失败！')
          }
          this.progressInfo = res.data
         console.log(this.progressInfo);
       }
      }
    }
</script>

<style scoped>

</style>
